<?php
if(!empty($this->group_datas['meta_keywords'])) { $this->headMeta()->setName('keywords',$this->group_datas['meta_keywords']);}
if(!empty($this->group_datas['meta_desc'])) { $this->headMeta()->setName('description',$this->group_datas['meta_desc']); } 
if(!empty($this->group_datas['property_name'])) { $this->headTitle()->headTitle($this->escape($this->menu_info['menu_name']),'SET'); }
echo $this->headScript()->setFile($this->baseUrl().'/js/jquery/table-sorter/jquery.dataTables.js');
echo $this->headScript()->setFile($this->baseUrl().'/js/jquery/jtruncate/jquery.jtruncate.pack.js');
echo $this->headLink()->setStylesheet($this->baseUrl().'/css/jqueryCSS/table-sorter/pagination_table.css');
$version = Zend_Registry::get('version');
$front_template = Zend_Registry::get('front_template');

$business_type_db = new Property_Model_DbTable_BusinessType();
$cat_Info = new Property_Model_DbTable_Category();
$mem_db = new Members_Model_DbTable_MemberList();
$state_db = new Property_Model_DbTable_State();
$area_db = new Property_Model_DbTable_Area();
$country_db = new Property_Model_DbTable_Country();
$review_helper = new Review_View_Helper_Review();
$maximum_stars_digit = $this->translator->translator('maximum_stars_digit');
// 1ist param options are : like, inline, plus_minus, horizontal, triangle
$vote = new Vote_Controller_Helper_ShowVoteButton('inline','property_page' );

$global_conf = Zend_Registry::get('global_conf');
$currency = new Zend_Currency($global_conf['default_locale']);

$property_type_arr = explode(',', $this->translator->translator('property_front_page_rent_id'));

function property_truncate($phrase,$start_words, $max_words)
{
   $phrase_array = explode(' ',$phrase);
   if(count($phrase_array) > $max_words && $max_words > 0)
	  $phrase = implode(' ',array_slice($phrase_array, $start_words, $max_words)).'...';  
   return $phrase;
}
?>
<script type="text/javascript">


$(document).ready(function() {

		text_truncate();
		/****************************Sorting Table Start*********************/
		var oTable = $("#sortTable").dataTable({
					"bPaginate": true,
					"aLengthMenu" : [ 10, 25, 50, 100 ],
					"sPaginationType": "full_numbers",
					"bDestroy":true,
					"bLengthChange": true,
					"bSearchable": true,
					"bFilter": false,
					"bSort": false,
					"bInfo": false,
					"bAutoWidth": true,
					"bProcessing": false,
					"bSortClasses": true,
					"bStateSave": false,
					"bServerSide": false,
					"aaSorting": [[ 0, "asc" ]],				
					"aoColumnDefs": [ 
						{ "bSortable": false, "bSortClasses": false,  "aTargets": [ 0 ] }
					],
					"oLanguage" : { "sSearch": "<?php echo $this->translator->translator('jquery_filter'); ?>" }
				}); 	
				
		/****************************Sorting Table End*********************/
		
		function getFormData()
		{
			var fieldObj = {};
			var filename = '';
			var filevalue = '';
			$.each($('#formSearch').serializeArray(), function(i, field) {	
				if(field.name.match(/\[\]$/))
				{
					var filearr = field.name.split('[]');
					filename = filearr[0];
					filevalue = $('#'+filename).val();
				}
				else
				{
					filename 	= 	field.name;
					filevalue 	= 	field.value;
				}			
				fieldObj[filename] =  filevalue;			
			});
			return fieldObj;
		}
		
		$('select.country_id').change(function() {	
			if($('select.country_id option:selected').val() == 'any' || $('select.country_id option:selected').val() =='')
			{
				$('select.area_id').html('<option value="any"><?php echo $this->translator->translator("property_select_area"); ?></option>');	
				$('select.state_id').html('<option value="any"><?php echo $this->translator->translator("property_select_state"); ?></option>');
			}
			else
			{	
				$.ajax({
					  url: "<?php echo $this->url( array('module' =>'Property','controller' => 'frontend', 'action'     => 'states' ), 'adminrout',    true) ?>",
					  type: 'POST',
					  data: { id: $('select.country_id option:selected').val() },
					  beforeSend: function(){						
								$('select.state_id').html('<option value="any"><?php echo $this->translator->translator("common_loading_language"); ?></option>');
								$('select.area_id').html('<option value="any"><?php echo $this->translator->translator("property_select_area"); ?></option>');			
								$('#state_id_err').html('<img src="images/ajax_loader7.gif" border="0" width="15" height="15" />');	
							 },
					  success: function(response){
						//alert(response);
						var json_arr = eval("("+response+")");
						var option = '<option value="any"><?php echo $this->translator->translator("property_select_state"); ?></option>';				
						if(json_arr.status == 'ok')
						{
							for(var i = 0;i<json_arr.states.length;i++)
							{
								option += '<option value="'+json_arr.states[i].state_id+'" >'+stripslashes(json_arr.states[i].state_name)+'</option>';
							}
							$('select.state_id').html(option);
						}
						else
						{
							$('select.state_id').html('<option value="any">'+json_arr.msg+'</option>');
						}
						$('#state_id_err').html('');
					  }
				});
			}
		});
		
		$('select.state_id').change(function() {		
					
			if($('select.state_id option:selected').val() == 'any' || $('select.state_id option:selected').val() == '')
			{
				$('select.area_id').html('<option value="any"><?php echo $this->translator->translator("property_select_area"); ?></option>');
			}
			else
			{
				$.ajax({
					  url: "<?php echo $this->url( array('module' => 'Property', 'controller' => 'frontend', 'action'     => 'areas' ), 'adminrout',    true) ?>",
					  type: 'POST',
					  data: { id: $('select.state_id option:selected').val() },
					  beforeSend: function(){						
							$('select.area_id').html('<option value="any"><?php echo $this->translator->translator("common_loading_language"); ?></option>');
							$('#area_id_err').html('<img src="images/ajax_loader7.gif" border="0" width="15" height="15" />');	
							},
					  success: function(response){
						//alert(response);
						var json_arr = eval("("+response+")");
						var option = '<option value="any"><?php echo $this->translator->translator("property_select_area"); ?></option>';				
						if(json_arr.status == 'ok')
						{
							for(var i = 0;i<json_arr.cities.length;i++)
							{
								option += '<option value="'+json_arr.cities[i].city_id+'" >'+stripslashes(json_arr.cities[i].city)+'</option>';
							}
							$('select.area_id').html(option);
						}
						else
						{
							$('select.area_id').html('<option value="any">'+json_arr.msg+'</option>');
						}
						$('#area_id_err').html('');
					  }
				});
			}
		});	
			
		$('input.search_btn').click(function(){
			var self = this;
			var formData = getFormData();
			
			$.ajax({
					 url: "<?php echo $this->url( array('module'=> 'Property', 'controller' => 'frontend', 'action'     => 'search' ), 'adminrout',    true) ?>",
					 type: 'POST',
					 data: formData,
					 beforeSend: function(){				 	
						$('#loader_img').html('<img src="images/ajax_loader7.gif" width="12" height="12" border="0" />');
					 },
					 success: function(response) 
					 {
						//alert(response);
						var json_arr = eval("("+response+")");						
						if(json_arr.status == 'ok')
						{						
							putSearchResult(oTable,json_arr.search_data);						
						}
						else
						{
							oTable.fnClearTable();
							//openMsgDialog(json_arr.msg);
						}
						$('#loader_img').html('');
					 }				
			});
		});
});
function stripslashes(str) 
{
	str=str.replace(/\\'/g,'\'');
	str=str.replace(/\\"/g,'"');
	str=str.replace(/\\0/g,'\0');
	str=str.replace(/\\\\/g,'\\');
	return str;
}
function text_truncate()
{
	$('span.jTruncate').jTruncate({  
		length:  300,  
		minTrail: 0,  
		moreText: "[<?php echo html_entity_decode($this->translator->translator('common_see_all'), ENT_QUOTES, "UTF-8"); ?>]",  
		lessText: "[<?php echo html_entity_decode($this->translator->translator('common_hide'), ENT_QUOTES, "UTF-8"); ?>]",  
		ellipsisText: "",  
		moreAni: "fast",  
		lessAni: 2000  
	});
}

</script>

<?php 
$allow_obj = new Property_View_Helper_Allow();
if (!$allow_obj->allowRule('group',null,null,$this->group_datas['role_id'])) : ?>
<?php echo $this->translator->translator('Member_Access_deny_desc'); ?>
<?php else : 

$property_title_name = ($this->menu_info) ? $this->escape($this->menu_info['menu_name']) : $this->escape($this->group_datas['property_name']);
?>

<div class="mod">
	<div class="property-list-icon">
        <h1>
          <?php echo $this->translator->translator('property_front_page_list'); ?><?php echo strtoupper(' ('.$property_title_name.')'); ?>
        </h1>
    </div>
        
    <div class="social">
      	<!-- AddThis Button BEGIN -->
        <div class="addthis_toolbox addthis_default_style">
        <a class="addthis_button_facebook_like" fb:like:layout="button_count"></a>
        <a class="addthis_button_tweet"></a>
        <a class="addthis_button_google_plusone" g:plusone:size="medium"></a>
        <a class="addthis_counter addthis_pill_style"></a>
        </div>
        <script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=xa-4e89660c7edb029a"></script>
    	<!-- AddThis Button END -->
    </div>
    
    <div class="clear"></div>
	<table id="sortTable" width="100%" border="0" align="center" cellpadding="0" cellspacing="0" >
        <tbody>
        	<?php
            foreach($this->view_datas as $entry)
            {
                $property_image_val_arr = explode(',',$entry['property_image']);
                $property_image_no = (empty($property_image_val_arr[0])) ? '0' : count($property_image_val_arr);
                if($this->escape($entry['property_primary_image']))
                { 
                    $thumb_image = 'data/frontImages/property/property_image/'.$this->escape($entry['property_primary_image']); 
                }
                else
                { 
                    if($this->escape($entry['property_image']))
                    {
                        $thumb_image = 'data/frontImages/property/property_image/'.$this->escape($property_image_val_arr[0]); 
                    }
                    else
                    {
                        $thumb_image = 'application/layouts/scripts/'.$front_template['theme_folder'].'/images/mod_property_img/no_image.png'; 
                    }		
                }
                if($this->group_datas['file_thumb_width'] && ($this->group_datas['file_thumb_resize_func'] == 'resizeToWidth' || $this->group_datas['file_thumb_resize_func'] == 'resize'))
                { 
                    $width = 'width="'.$this->escape($this->group_datas['file_thumb_width']).'"'; 
                }
                else
                {
                    $width = '';
                } 
                if($this->group_datas['file_thumb_height'] && ($this->group_datas['file_thumb_resize_func'] == 'resizeToHeight' || $this->group_datas['file_thumb_resize_func'] == 'resize'))
                { 
                    $height = 'height="'.$this->escape($this->group_datas['file_thumb_height']).'"'; 
                } 
                else
                {
                    $height = '';
                }
				$featured_class = ($entry['featured'] == '1') ? 'products-featured' : '' ;
           	?>
        	<tr>
            	<td>
                	<div class="products-list">
                    	<!-- list Header Start -->
                        <div class="list-header">
                       		<div class="header-row">
                            	<div class="header-left">
                                	<span class="title-small"><a href="<?php echo $this->url(array('module' => 'Property','controller' =>'frontend', 'action' => 'details','property_title' => $this->escape($entry['property_title']) ),'Property-details/:property_title',true); ?>" class="preview" title="<?php echo $this->escape($entry['property_name']); ?>" link=""><?php echo $this->escape(property_truncate($entry['property_name'], 0, 5)); ?></a></span><br />
                                  <span class="info"><?php if(!empty($entry['feature_room_no'])){ echo (int)$this->escape($entry['feature_room_no']).' '.$this->translator->translator('property_front_page_room'); } ?></span>  
                                  </div>
                            
                            	<div class="header-middle">
                                    <span class="products-mark"><?php $type_infos = $business_type_db->getBusinessTypeInfo($entry['property_type']); echo $this->translator->translator('property_front_page_property_for'); ?></span>&nbsp;<span class="products-type"><?php echo $this->escape($type_infos['business_type']); ?></span>
                                </div>
                            
                            	<div class="header-right">                                                
									<?php 
                                        if(!empty($this->group_datas['review_id'])){ 
                                        $review_no = $review_helper->getNumOfReviews($entry['id'], $this->escape($this->group_datas['review_id']));
                                    ?><span class="products-write-review"><a href="<?php echo $this->url( array('module' => 'Review','controller' => 'frontend', 'action'     => 'write', 'group_id' => $this->escape($this->group_datas['review_id']), Eicra_File_Constants::ITEM_ID => $entry['id'] ), 'Review-Write/:group_id/:item_id',    true); ?>"><?php echo $this->translator->translator('common_write_review'); ?></a></span> &nbsp; <span class="products-review-count"><a href="<?php echo $this->url(array('module' => 'Property','controller' =>'frontend', 'action' => 'details','property_title' => $this->escape($entry['property_title']),'tab' => 7 ),'Property-details/:property_title/:tab',true); ?>"><?php echo $this->translator->translator('common_review_no',htmlentities($review_no)); ?></a></span> <?php } ?>
                                </div>
                          	</div>
                        </div>
                        <!-- list Header End -->
                        
                        <!-- list Body Start --> 
                            <div class="body-container <?php echo $featured_class; ?>">
                                 <div class="left-content">
                                        <div class="img-wrapper">
                                        	<a href="<?php echo $this->url(array('module' => 'Property','controller' =>'frontend', 'action' => 'details','property_title' => $this->escape($entry['property_title']) ),'Property-details/:property_title',true); ?>" class="preview" link="<?php echo $thumb_image; ?>" width="250" title="<?php echo $this->escape($entry['property_name']); ?>"><img src="<?php echo $thumb_image; ?>" <?php echo $width; ?> <?php echo $height; ?> border="0" class="thumb" /></a>
                                            <div class="photo-count-container">
                                                <div class="photo-count">
                                                    <a href="<?php echo $this->url(array('module' => 'Property','controller' =>'frontend', 'action' => 'details','property_title' => $this->escape($entry['property_title']),'tab' => 1 ),'Property-details/:property_title/:tab',true); ?>" title="<?php echo $this->translator->translator('property_front_page_click_view_photos'); ?>"><?php echo $this->translator->translator('property_front_page_property_photo_no', $property_image_no); ?></a>
                                                </div>
                                            </div>                                            
                                        </div>
                                        
                                        <h2>
                                            <a href="<?php echo $this->url(array('module' => 'Property','controller' =>'frontend', 'action' => 'details','property_title' => $this->escape($entry['property_title']) ),'Property-details/:property_title',true); ?>" class="preview" title="<?php echo $this->escape($entry['property_name']); ?>" link=""><?php echo $this->escape(property_truncate($entry['property_name'], 0, 5)); ?></a>
                                        </h2>
                                        
                                        <div class="products-stars">
										<?php
                                            for($i = 1; $i < $maximum_stars_digit; $i++)
                                            {
                                                $property_stars = ($i <= $this->escape($entry['stars'])) ? "<img src='application/layouts/scripts/".$front_template['theme_folder']."/images/mod_property_img/star-active.png' border='0' />" : "<img src='application/layouts/scripts/".$front_template['theme_folder']."/images/mod_property_img/star-inactive.png' border='0'/>";
                                                echo $property_stars.'&nbsp;';
                                            }
                                        ?>
                                        </div>
                                        
                                        <div class="products-desc">
                                           	<p><?php echo $this->translator->translator('property_front_page_property_location'); ?></p> <?php $states = $state_db->getStateInfo($entry['state_id']); $areas = $area_db->getAreaInfo($entry['area_id']); echo $this->escape($states['state_name']); ?><br />
                                            <p><?php echo $this->translator->translator('property_front_page_property_country'); ?></p> <?php $countries = $country_db->getCountryName($entry['country_id']); echo $this->escape($countries['value']); ?><br />

                                            <p><?php echo $this->translator->translator('property_front_page_property_desc'); ?></p>
                                            <span class="jTruncate"><?php echo $this->escape(strip_tags($entry['property_desc'])); ?></span>
                                        </div>
                                 </div>
                                 
                                 <div class="right-content">
                                 	<span class="products-price">
                                        <span>
                                              <?php  echo $this->translator->translator('property_front_page_price');  ?>
                                            </span>
                                            <span>
                                              <?php

                                             $number = $this->price($this->escape($entry['property_price']));
                                             echo number_format($number, 0, ',', '.');
                       
                                             ?>
                                           </span>
                                   </span>
                                    <ul class="products-options">
                                    	<?php
										if(!empty($property_type_arr[0]) && in_array($entry['property_type'], $property_type_arr))
										  {
										?>
										
										<?php
										  }
										  if(!empty($entry['feature_bathroom']))
										  {
										?>	
                                        <li class="bathroom"><?php  echo $this->translator->translator('maid_age').' '.(int)$this->escape($entry['feature_bathroom']).' '.$this->translator->translator('property_front_page_bathroom'); ?></li>
                                       	<?php
										  }
										?>
                                        
                                        <li class="kitchen"><?php $input = $this->escape($entry['feature_kitchen']); echo str_replace('_', ' ', $input); ?></li>
                                        <li class="garden">
                                              <?php
                                                                            $search  = array('_', 'doctor');
                                                                            $replace = array(' ', 'doctor\'s');
                                                                            $subject = $this->escape($entry['feature_garden']);
                                                                            echo str_replace($search, $replace, $subject);
                                                                          ?>
                                           </li>                                         

                                        <li class="garage"><?php $input = $this->escape($entry['feature_garage']); echo str_replace('_', ' ', $input); ?></li>
                                    </ul>
                                    <div class="products-vote">
                                    	<p><?php echo $this->translator->translator('property_front_page_label_voting'); ?></p>
                                		<span><?php  $vote->showButton($entry['id'] , $this->escape($entry['property_name'])); ?></span>
                                    </div>                            
                                 </div>    
                        </div>
                        <!-- list Body End -->
                        
                        <!-- list footer start -->
                        <div class="list-footer">
                            <div class="footer-left">
                                
                                <a href="<?php echo $this->url(array('module' => 'Property','controller' =>'frontend', 'action' => 'details','property_title' => $this->escape($entry['property_title']),'tab' => 2 ),'Property-details/:property_title/:tab',true); ?>"><?php echo $this->translator->translator('property_front_page_property_fpan'); ?></a>  | 
                                
                                <a href="<?php echo $this->url(array('module' => 'Property','controller' =>'frontend', 'action' => 'details','property_title' => $this->escape($entry['property_title']),'tab' => 1 ),'Property-details/:property_title/:tab',true); ?>"><?php echo $this->translator->translator('property_front_page_property_photo'); ?></a> | 
                                <a href="<?php echo $this->url(array('module' => 'Property','controller' =>'emails', 'action' => 'friend','property_title' => $this->escape($entry['property_title']), 'form_id' => $this->translator->translator('email_to_friend_form_id') ),'Email-To-Friend/:property_title/:form_id',true); ?>"><?php echo $this->translator->translator('property_front_page_property_email_friend'); ?></a>
                            </div>
                        
                            <div class="footer-right">
                            	<span class="products-book-btn"><a href="<?php echo $this->url(array('module' => 'Property','controller' =>'emails', 'action' => 'owner','property_title' => $this->escape($entry['property_title']), 'form_id' => $this->translator->translator('contact_owner_form_id') ),'Contact-Owner/:property_title/:form_id',true); ?>"><?php echo $this->translator->translator('property_front_page_property_book'); ?></a></span>
                                        
                                <span class="products-details-btn"><a href="<?php echo $this->url(array('module' => 'Property','controller' =>'frontend', 'action' => 'details','property_title' => $this->escape($entry['property_title']) ),'Property-details/:property_title',true); ?>"><?php echo $this->translator->translator('property_front_page_property_more'); ?></a></span>
                            </div>
                        </div>
                    	<!-- list footer end -->
                    </div>	
                </td>
            </tr>
		 	<?php
            }
          	?>
        </tbody>
	</table>
  
    <div id="bottomPagination">
        <?php
            echo $this->paginationControl($this->view_datas, 'Sliding', 'frontend/group-pagination-flickr.phtml'); 	 
        ?>
    </div>
</div>
<?php endif; ?>	